//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//
// (C) Copyright 2006 Marvell International Ltd.
// All Rights Reserved
//



#ifndef __CLKMGR_H
#define __CLKMGR_H

#include "windows.h"
#include "xllp_defs.h"
#include "xllp_clkmgr.h"

typedef enum _tag_clock_type
{
    CLKMGR_TYPE_FIRST = 0,
    CLKMGR_SIDECAR    = CLKMGR_TYPE_FIRST,
    CLKMGR_OSSC_POUT,
    CLKMGR_MVED,
    CLKMGR_TYPE_END
} CLKMGR_CLOCK_TYPE;

#ifdef __cplusplus

// c++ only interface
class CClockManager
{
private:
    CLKMGR_CLOCK_TYPE m_type;
    HANDLE m_hEvent;
    CRITICAL_SECTION m_cs;
    int m_refCnt;
    bool m_valid;
    DWORD m_instance;
protected:
    // error typedef, currently internal use only
    typedef enum
    {
        SUCCESS = 0,
        ERROR_GENERAL = -1,
        ERROR_GET_EVENT = -2,
        ERROR_INVALID_TYPE = -3
    } _ERRTYPE;
    _ERRTYPE prepare_or_abort();
    _ERRTYPE control(bool en);
public:
    CClockManager(CLKMGR_CLOCK_TYPE type);
    virtual ~CClockManager();
    void enable() { control(true); }
    void disable() { control(false); }
};

#endif

// C style interface
typedef void* CLKMGR;
#define SIDECAR CLKMGR
#define PSIDECAR CLKMGR *
#define InitSidecar(a) InitClkMgr(CLKMGR_SIDECAR,a)
#define EnableSidecar(a) EnableClock(a)
#define DisableSidecar(a) DisableClock(a)
#define ReleaseSidecar(a) ReleaseClkMgr(a)

#ifdef __cplusplus
extern "C"{
#endif 
int InitClkMgr(CLKMGR_CLOCK_TYPE type, CLKMGR *clkmgr);
void ReleaseClkMgr(CLKMGR *clkmgr);
void EnableClock(CLKMGR *clkmgr);
void DisableClock(CLKMGR *clkmgr);
#ifdef __cplusplus
}
#endif 
#endif



